package com.ztools.pc.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.sys.Role;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.common.util.pc.TokenAuthorization;
import com.ztools.pc.service.sys.RoleService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author:一口香菜
 * @Date: 2023/3/4  21:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/role")
public class RoleController {

    @Resource
    private RoleService roleService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/list")
    @TokenAuthorization("/sys/role/search")
    public Result findList(PageUtil<Role> pageUtil) {
        Page<Role> list = roleService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/add")
    @TokenAuthorization("/sys/role/add")
    public Result add(@RequestBody Role role) {
        boolean b = roleService.save(role);
        return b ? Result.success("新增成功") : Result.error("新增失败");
    }

    @RequestMapping("/delete")
    @TokenAuthorization("/sys/role/delete")
    public Result delete(@RequestBody Role role) {
        boolean b = roleService.delete(role);
        return b ? Result.success("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/update")
    @TokenAuthorization("/sys/role/update")
    public Result update(@RequestBody Role role) {
        boolean b = roleService.update(role);
        return b ? Result.success("修改成功") : Result.error("修改失败");
    }

}
